package com.jyw.web.controller.system;

import com.jyw.common.annotation.Log;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.enums.BusinessType;
import com.jyw.common.valid.CommonValidList;
import com.jyw.system.domain.SysReceiveDepartConfig;
import com.jyw.system.domain.vo.SysReceiveDepartConfigVo;
import com.jyw.system.domain.vo.SysReceiveDepartDetailVo;
import com.jyw.system.service.ISysReceiveDepartConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author Created by ZhangCheng on 2023/08/17 (系统工单接单科室配置)
 */
@Api(tags = "系统工单接单科室配置")
@RestController
@RequestMapping("/system/receiveDepartConfig")
public class SysReceiveDepartConfigController {

    @Resource
    private ISysReceiveDepartConfigService sysReceiveDepartConfigService;

    /**
     * 获取工单接单科室启用配置
     *
     * @return
     */
    @GetMapping("/getConfig")
    @ApiOperation("获取工单接单科室启用配置")
    public CommonResult<SysReceiveDepartDetailVo> getConfig() {
        return CommonResult.success(sysReceiveDepartConfigService.getDefaultConfig());
    }

    /**
     * 修改工单接单科室启用配置
     *
     * @param sysReceiveDepartDetailVo
     * @return
     */
    @Log(title = "修改工单接单科室启用配置", businessType = BusinessType.UPDATE)
    @PutMapping("/updateConfig")
    @ApiOperation("修改工单接单科室启用配置")
    public CommonResult updateConfig(@RequestBody @Valid SysReceiveDepartDetailVo sysReceiveDepartDetailVo) {
        sysReceiveDepartConfigService.updateConfig(sysReceiveDepartDetailVo);
        return CommonResult.success();
    }

    /**
     * 查询所有系统工单接单科室配置
     */
    @GetMapping("/queryAllList")
    @ApiOperation("查询所有系统工单接单科室配置")
    public CommonResult<List<SysReceiveDepartConfigVo>> queryAllList() {
        List<SysReceiveDepartConfigVo> list = sysReceiveDepartConfigService.queryAllList();
        return CommonResult.success((list));
    }

    /**
     * 新增系统工单接单科室配置
     *
     * @param sysReceiveDepartConfig
     * @return
     */
    @Log(title = "新增系统工单接单科室配置", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @ApiOperation("新增系统工单接单科室配置")
    public CommonResult add(@RequestBody @Valid SysReceiveDepartConfig sysReceiveDepartConfig) {
        sysReceiveDepartConfigService.insert(sysReceiveDepartConfig);
        return CommonResult.success();
    }

    /**
     * 批量新增系统工单接单科室配置
     *
     * @param configList
     * @return
     */
    @Log(title = "批量新增系统工单接单科室配置", businessType = BusinessType.INSERT)
    @PostMapping("/saveList")
    @ApiOperation("批量新增系统工单接单科室配置")
    public CommonResult addList(@RequestBody @Valid CommonValidList<SysReceiveDepartConfig> configList) {
        return CommonResult.success(sysReceiveDepartConfigService.insertList(configList));
    }

    /**
     * 删除工单接单科室
     */
    @Log(title = "删除系统工单接单科室配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除系统工单接单科室配置")
    public CommonResult remove(@PathVariable Long[] ids) {
        return CommonResult.success(sysReceiveDepartConfigService.deleteBatchByIds(ids));
    }
}
